package com.ktgj.customer.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ktgj.customer.domain.InsuranceType;
import com.ktgj.customer.service.IInsuranceTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 保险类型
Controller
 * 
 * @author ruoyi
 * @date 2021-07-27
 */
@ControllerAdvice
@RestController
@RequestMapping("/insuranceType")
public class InsuranceTypeController extends BaseController
{
    @Autowired
    private IInsuranceTypeService insuranceTypeService;

    /**
     * 查询保险类型
列表
     */
    @PreAuthorize(hasPermi = "system:type:list")
    @GetMapping("/list")
    public TableDataInfo list(InsuranceType insuranceType)
    {
        startPage();
        List<InsuranceType> list = insuranceTypeService.selectInsuranceTypeList(insuranceType);
        return getDataTable(list);
    }

    /**
     * 导出保险类型
列表
     */
    @PreAuthorize(hasPermi = "system:type:export")
    @Log(title = "保险类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InsuranceType insuranceType) throws IOException
    {
        List<InsuranceType> list = insuranceTypeService.selectInsuranceTypeList(insuranceType);
        ExcelUtil<InsuranceType> util = new ExcelUtil<InsuranceType>(InsuranceType.class);
        util.exportExcel(response, list, "保险类型数据");
    }

    /**
     * 获取保险类型
详细信息
     */
    @PreAuthorize(hasPermi = "system:type:query")
    @GetMapping(value = "/{insTypeId}")
    public AjaxResult getInfo(@PathVariable("insTypeId") Long insTypeId)
    {
        return AjaxResult.success(insuranceTypeService.selectInsuranceTypeById(insTypeId));
    }

    /**
     * 新增保险类型

     */
    @PreAuthorize(hasPermi = "system:type:add")
    @Log(title = "保险类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InsuranceType insuranceType)
    {
        return toAjax(insuranceTypeService.insertInsuranceType(insuranceType));
    }

    /**
     * 修改保险类型

     */
    @PreAuthorize(hasPermi = "system:type:edit")
    @Log(title = "保险类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InsuranceType insuranceType)
    {
        return toAjax(insuranceTypeService.updateInsuranceType(insuranceType));
    }

    /**
     * 删除保险类型

     */
    @PreAuthorize(hasPermi = "system:type:remove")
    @Log(title = "保险类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{insTypeIds}")
    public AjaxResult remove(@PathVariable Long[] insTypeIds)
    {
        return toAjax(insuranceTypeService.deleteInsuranceTypeByIds(insTypeIds));
    }

    /**
     * 保险类型列表
     * */
    @PostMapping("/insuranceTypeList")
    public AjaxResult insuranceTypeList() {
        List<InsuranceType> insuranceTypeList = insuranceTypeService.insuranceTypeList();
        return AjaxResult.success(insuranceTypeList);
    }
}
